;; The first four lines of this file were added by Dracula.
;; They tell DrScheme that this is a Dracula Modular ACL2 program.
;; Leave these lines unchanged so that DrScheme can properly load this file.
#reader(planet "reader.rkt" ("cce" "dracula.plt") "modular" "lang")
(require "iimage.lisp")
(require "icommon.lisp")
(require "inegative.lisp")

(module Mnegative
  (import IImage)
  (import ICommon)
  
  ; Replaces each pixel's color in the tree with its negative color.
  ; pre: tree - the bitmap tree
  ;      x - column of pixel
  ;      y - row of pixel
  ;      width - positive integer width of the tree
  ;      height - positive integer height of the tree
  ; post: a new bitmap tree representing a photonegative of the image
  (defun invertPixels (tree x y width height)
    (if (<= y height)
        (if (<= x width)
            (let* ((RGB (getPixel tree x y))
                   (newR (- 255 (car RGB)))
                   (newG (- 255 (cadr RGB)))
                   (newB (- 255 (caddr RGB))))
              (invertPixels (insertPixel tree x y newR newG newB)
                            (+ x 1) y width height))
            (invertPixels tree 1 (+ y 1) width height))
        tree))
  
  ; Uses invertPixels to get the photonegative of a bitmap and returns a multiple
  ; value of the tree representing the new image and an appropriate completion message.
  (defun MainNegative (tree)
    (mv (invertPixels tree 1 1 (getWidth tree) (getHeight tree))
        (list "Negative successful!")))
  
  (export INegative))